package com.gxd.business.controller;

import com.gxd.business.domain.Product;
import com.gxd.business.domain.qco.ProductQco;
import com.gxd.business.service.ProductService;
import com.gxd.common.core.controller.BaseController;
import com.gxd.common.core.domain.AjaxResult;
import com.gxd.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * @author gxd
 * @since 2025/6/13
 */
@RestController
@RequestMapping("/product")
@Api(tags = "产品管理")
public class ProductController extends BaseController {

    @Autowired
    private ProductService productService;

    @ApiOperation("分页列表-产品列表")
    @PostMapping("/pageList")
    public TableDataInfo pageList(@ApiParam(value = "产品查询条件") @RequestBody ProductQco qco) {
        List<Product> productList = productService.pageList(qco);
        return getDataTable(productList);
    }

    @ApiOperation("详情信息-根据Id获取产品详情信息")
    @ApiImplicitParam(name = "id", value = "产品Id", required = true, dataType = "String", paramType = "path")
    @GetMapping("/getById/{id}")
    public AjaxResult getById(@NotEmpty(message = "产品id不能为空") @PathVariable String id) {
        return success(productService.getDetailById(id));
    }

    @ApiOperation("添加或修改-产品信息")
    @PostMapping("/addOrEdit")
    public AjaxResult addOrEdit(@ApiParam(value = "产品实体", required = true) @Valid @RequestBody Product product) {
        return success(productService.addOrEdit(product));
    }

    @ApiOperation("删除-产品信息（支持批量）")
    @ApiImplicitParam(name = "ids", value = "产品Id（多个需逗号分隔）", required = true, allowMultiple = true, dataType = "String", paramType = "path")
    @DeleteMapping("/removeById")
    public AjaxResult removeById(@RequestParam("ids") String ids) {
        return toAjax(productService.deleteById(ids));
    }
}
